﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Service
{
    internal class CheckBalance : ICommand
    {
        DataLayer.DBFacade DB;
        Model.Account account;
        double balance;

        public double Balance { get { return balance; } } 

        public CheckBalance(Model.Account account)
        {
            DB = new DataLayer.DBFacade();
            this.account = account;
        }

        public bool Execute()
        {
            string query = "SELECT  Balance FROM account a  where accounttype='" + Model.CurrentSession.accountType + "' and accountno='" + account.AccountNumber + "'";
            string bal=DB.ReadScalar(query);
            balance = Convert.ToDouble(string.IsNullOrEmpty(bal) ? "-1" : bal);
            return balance > 0;
        }

        public bool Undo()
        {
            throw new NotImplementedException();
        }
    }
}